home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / cc02.zip / FRESPACE.C < prev    next >
Text File  |  1985-10-31  |  2KB  |  120 lines

  1. /*  free.c
  2.     Finds free space on a disk drive
  3.  
  4.     Invocation:
  5.  
  6.         free <drive>
  7.         where <drive> is a valid drive descriptor.
  8.  
  9. */
  10.  
  11. #include "ctype.h"
  12. #include "stdio.h"
  13.  
  14. main(argc,argv)
  15.  
  16. int     argc;
  17. char    *argv[];
  18.  
  19. {
  20.  
  21. char    drive;
  22. long    space,kbytes;
  23. int     driveno,clusters;
  24.  
  25.         if (argc-2)
  26.          {
  27.         printf(" Invalid command line format\n");
  28.         printf(" Invoke with   free <drive letter>\n");
  29.         exit(1);
  30.          }
  31.  
  32.         else
  33.         {
  34.         drive = toupper(*argv[1]);              /* get drive letter */
  35.         driveno = (int)((drive)-'A'+1);
  36.         space = free_sectors(driveno); /* print free space */
  37.         if (space == -1)        {
  38.                                 printf("Invalid drive letter\n");
  39.                                 exit(1);
  40.                                 }
  41.         else
  42.         printf( "\nDrive %c has %ld sectors remaining\n",drive,space);
  43.         clusters = free_clusters(driveno);
  44.         printf("                 %d clusters\n",clusters);
  45.         kbytes = free_kbytes(driveno);
  46.         printf("                 %ld Kbytes\n",kbytes);
  47.         }
  48. }
  49.  
  50. free_sectors(des)
  51.  
  52. int     des;
  53.  
  54. {
  55.  
  56. long    freesec;
  57.  
  58.         freesec = get_disk_free_space(des);
  59.         return(freesec);
  60.  
  61. }
  62.  
  63. get_disk_free_space(driveno)
  64.  
  65. int     driveno;
  66.  
  67. {
  68.  
  69. #asm
  70.  
  71.         mov     dx,[bp+8]
  72.         mov     ah,36h
  73.         int     21h
  74.         cmp     ax,-1
  75.         je      gdfs0
  76.         mul     bx
  77.         jmp     short gdfsx
  78.  
  79. gdfs0:
  80.         mov     dx,-1
  81. gdfsx:
  82.  
  83. #endasm
  84.  
  85. }
  86.  
  87. free_clusters(driveno)
  88.  
  89. int     driveno;
  90.  
  91. {
  92.  
  93. #asm
  94.         mov     dx,[bp+8]
  95.         mov     ah,36h
  96.         int     21h
  97.         mov     ax,bx
  98. #endasm
  99.  
  100. }
  101.  
  102. free_kbytes(driveno)
  103.  
  104. int     driveno;
  105.  
  106. {
  107.  
  108. #asm
  109.  
  110.         mov     dx,[bp+8]
  111.         mov     ah,36h
  112.         int     21h
  113.         mul     bx
  114.         mov     bx,2
  115.         idiv    bx
  116.  
  117. #endasm
  118.  
  119. }
  120.